package com.cheng.spider.request;

import com.cheng.spider.header.HeaderSource;
import org.apache.http.client.methods.HttpRequestBase;

public abstract class HeaderConfigurableRequester extends ConfigurableRequester {

    private HeaderSource headerSource;

    public HeaderConfigurableRequester() {
        headerSource = initHeaderSource();
    }

    protected abstract HeaderSource initHeaderSource();

    @Override
    public void configHeaders(HttpRequestBase request) {
        if (headerSource != null)
            request.setHeaders(headerSource.getHeaders());
    }

    public void setHeaderSource(HeaderSource headerSource) {
        this.headerSource = headerSource;
    }
}
